<?php
/**
 * Created by PhpStorm.
 * User: 江雪
 * Date: 2019/4/17
 * Time: 21:25
 */

namespace App\HttpController\V1;


class Snow extends Auth
{
    /**
     * 字段 (列表接口)
     */
    public function log_field($type){
        $field=[
            1=> 'id,study_title,author_id,image,browse,time,create_time',
            2=> 'id,study_title,image,browse,`like`,create_time',
            3=> 'id,study_title,image,browse,time,introduce',
            4=> 'id,study_title,author_id,image,browse,time',
            5=> 'id,study_title,user_id,image,browse,`like`,favorite,comm_num,content,create_time',
        ];
        return $field[$type];
    }

    /**
     * 类型
     * 1名师更多 2文章 3国学 4大学生 5问答
     */
    public function log_type($type){
        $arr=[1=>5,2=>8,3=>9,4=>10,5=>11];
        return $arr[$type];
    }

    /**
     * 当前用户是否点赞
     */
    public function likes($mode,$study_id,$user_id){
        #判断自己是否点赞，收藏
        $study_like=$mode
            ->where('study_id',$study_id)
            ->where('user_id',$user_id)
            ->getOne('study_like');
        if (!empty($study_like)){
            $info=1;#已点赞
        }else{
            $info=0;
        }
        return $info;
    }
    /**
     * 当前用户是否关注
     */
    public function follow($mode,$study_id,$user_id){
        $users_collection=$mode
            ->where('to_user_id',$study_id)
            ->where('user_id',$user_id)
            ->getOne('users_follow');
//        dump($users_collection);
        if (!empty($users_collection)){
            $info=1;#已收藏
        }else{
            $info=0;
        }
        return $info;
    }
    /**
     * 当前用户是否收藏
     */
    public function collection($mode,$study_id,$user_id){
        $users_collection=$mode
            ->where('class_id',$study_id)
            ->where('user_id',$user_id)
            ->getOne('users_collection');
//        dump($users_collection);
        if (!empty($users_collection)){
            $info=1;#已收藏
        }else{
            $info=0;
        }
        return $info;
    }

    /**
     * 增加浏览量video_share
     */
    public function browseinc($mode,$study_id){
        $mode->where('id',$study_id)->setInc('study','browse');
    }
    /**
     * 搜索历史
     */
    public function search_log($mode,$study_id,$user_id){

    }

    /**
     * 我的收藏字段 (列表接口)
     */
    public function my_field($type){
        $field=[
            1=> 'id,study_title,share_text,image,browse,create_time',
            2=> 'id,study_title,share_text,time,image,browse,introduce,create_time',
            3=> 'id,study_title,share_text,user_id,image,browse,introduce,`like`,favorite,comm_num,create_time',
            4=> 'id,study_title,share_text,image,introduce,summary,browse,time',
            5=> 'id,study_title,share_text,user_id,favorite,browse,comm_num,widths,heights,`like`,image,vip_video,video_img,create_time',
        ];
        return $field[$type];
    }

    /**
     * 增加浏览数量
     */
    public function setinc_l($model,$study_id){
        $sql = sprintf( "update `study` set `browse` = browse + %.2f  where id = %s", 1, $study_id );
        $model->rawQuery( $sql );
    }

}